package com.example.demo.leeCode;

import java.util.ArrayList;
import java.util.List;

public class MaxSuger {
    public static void main(String[] args) {
        int [] array = new int[]{2,3,5,1,3};
        int extraCandies = 3;
        List list = new MaxSuger().kidsWithCandies(array,extraCandies);
        System.out.println(list.toString());
    }
    public List<Boolean> kidsWithCandies(int[] candies, int extraCandies) {
        List<Boolean> list = new ArrayList<>(candies.length);
        int max = 0;
        //取出最大数
        for(int x : candies){
            if(x > max){
                max = x;
            }
        }
        //最大数减去最多获取数，得到当前对比数，放在循环外部，减少运算
        max = max - extraCandies;
        for(int x : candies){
            if(x < max){
                list.add(false);
            }else{
                list.add(true);
            }
        }

        return list;
    }
}
